<template>
  <div class="__goods-item">
    <div class="media">
      <img :src="data.Image" alt="">
    </div>
    <div class="content">
      <p class="name">{{data.Name}}</p>
      <div class="bottom">
        <span><b>¥</b>{{data.Price}}</span>
        <div class="handle-num">
          <Stepper
            v-model="data.Num"
            :min="0"
            :disable-input="true"
            @plus="onPlus"
            @minus="onMinus"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Stepper, Toast } from 'vant';
export default {
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  components: {
    Stepper 
  },
  methods: {
    onPlus() {
      if (this.data.IsMulti) {
        setTimeout(() => {
          this.data.Num -= 1;
        }, 0);
        this.$emit('select', {
          data: this.data,
          type: 'normal'
        });
      } else {
        this.$emit('change', {
          value: this.data.Num + 1,
          changeValue: 1,
          id: this.data.Id,
          type: 'normal',
          data: this.data
        });
      }
    },
    onMinus() {
      if (this.data.IsMulti) {
        setTimeout(() => {
          this.data.Num += 1;
        }, 0);
        Toast('多规格商品只能去购物车删除哦');
        return;
      }
      this.$emit('change', {
        value: this.data.Num - 1,
        changeValue: -1,
        id: this.data.Id,
        type: 'normal',
        data: this.data
      });
    },
  },
  created() {
  }
}
</script>
<style lang="less" scoped>
.__goods-item{
  .media{
    float: left;
    width: 200px;
    height: 200px;
    margin: 15px 20px;
    border-radius: 5px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .content{
    margin: 0 20px 0 240px;
    height: 230px;
    position: relative;
    .name{
      font-size: 30px;
      line-height: 36px;
      font-weight: 600;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }
    .handle-num{
      text-align: right;
    }
    .bottom{
      width: 100%;
      left: 0;
      position: absolute;
      bottom: 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}
</style>
<style lang="less">
.__goods-item{
  .van-stepper__input[disabled]{
    color: #333;
  }
}
</style>
